from langchain_community.chat_models import ChatTongyi
from langchain_core.prompts.chat import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain_core.prompts.prompt import PromptTemplate
from langchain.chains import LLMChain

import os

os.environ["DASHSCOPE_API_KEY"] = "sk-9d8f1914800e497f8717144e860f99bc"
# 调用模型
llm = ChatTongyi()

# 定义提示模板
human_message_prompt = HumanMessagePromptTemplate(
    prompt=PromptTemplate(
        input_variables=["content1", 'content2'],
        template="关于{content1}{content2}是什么?请中文回复我"
    ),
)

# 组装提示模板
chat_prompt_template = ChatPromptTemplate.from_messages([human_message_prompt])
chain = LLMChain(llm=llm, prompt=chat_prompt_template)
# 提问
res = chain.invoke({'content1': '苹果', 'content2': '笑话'})
print(res)
